import Cookies from 'js-cookie';
import { getInfo } from '@/api/info';

const fyInfo = {
  namespaced: true,
  state: {
    fyxx: {}
  },

  mutations: {
    SET_FYXX: (state, fyxx) => {
      state.fyxx = fyxx;
    },
  },

  actions: {
    // 获取房源信息
    getInfo({ commit }, fjh) {
      return new Promise((resolve, reject) => {
        getInfo(fjh).then(res => {
          Cookies.set('fyInfo', JSON.stringify(res.data))
          window.localStorage.setItem('fyInfo', JSON.stringify(res.data))
          commit('SET_FYXX', res.data)
          resolve(res.data)
        }).catch(error => {
          reject(error)
        })
      })
    },
  }
}

export default fyInfo
